package cn.controller;

import cn.pojo.App_category;
import cn.pojo.App_info;
import cn.pojo.App_version;
import cn.pojo.Data_dictionary;
import cn.service.app_category.App_categoryService;
import cn.service.app_info.App_infoService;
import cn.service.app_version.App_versionService;
import cn.service.data_dictionary.Data_dictionaryService;
import cn.tools.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/user_data")
public class User_dataController {
    @Resource
    private App_infoService app_infoService;
    @Resource
    private Data_dictionaryService data_dictionaryService;
    @Resource
    private App_categoryService app_categoryService;
    @Resource
    private App_versionService app_versionService;

    //手游审核查询
    @RequestMapping("/select")
    public  String select(HttpServletRequest request,App_info app_info, Integer pageIndex, HttpSession session){
        if(app_info.getStatus()==0){
            app_info.setStatus(1);
        }
        if(pageIndex==null){
            pageIndex=1;

        }

        Page page=new Page();
        page.setPageIndex(pageIndex);
        page.setPageSize(5);
        page.setPageTotal(app_infoService.getAppInfoCount(app_info.getSoftwareName(),app_info.getStatus()
                ,app_info.getCategoryLevel1(),app_info.getCategoryLevel2()
                ,app_info.getCategoryLevel3(),app_info.getFlatformId(),app_info.getDevId()));
        List<App_info> list=app_infoService.getAppInfoList(app_info.getSoftwareName(),app_info.getStatus()
                ,app_info.getCategoryLevel1(),app_info.getCategoryLevel2()
                ,app_info.getCategoryLevel3(),app_info.getFlatformId(),app_info.getDevId()
                ,page.getPageIndex(),page.getPageSize());
        List<Data_dictionary>status=data_dictionaryService.getData_dictionaryStatus();//状态list集合
        List<Data_dictionary>flatform=data_dictionaryService.getData_dictionaryFlatfrom();//所属平台list集合
        //列出一级分类列表，注：二级三级分类类别通过ajax异步获取
        List<App_category>list1=app_categoryService.getApp_category1();
        request.setAttribute("list",list);
        request.setAttribute("page",page);
        request.setAttribute("app_info",app_info);
        request.setAttribute("status",status);
        session.setAttribute("flatform",flatform);
        request.setAttribute("list1",list1);
        return "user_data";
    }

    //查询审核详情
    @RequestMapping("/view")
    public String view(Integer id,HttpServletRequest request){
        App_info app_info=app_infoService.getAPP_infoById(id);
        List<App_version>list=app_versionService.getApp_versionById(id);
        App_version app_version=list.get(0);
        request.setAttribute("app_info",app_info);
        request.setAttribute("app_version",app_version);
        return "user_data_view";
    }

    //审核通过
    @RequestMapping("/tstatus")
    public String tstatus(Integer id){
        data_dictionaryService.tStatus(id);
        return "redirect:/user_data/select";
    }
    //审核不通过
    @RequestMapping("/fstatus")
    public String fstatus(Integer id){
        data_dictionaryService.fStatus(id);
        return "redirect:/user_data/select";
    }
}
